/**
 * 
 */
package cn.suse.android.logic;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import cn.suse.android.entity.User;
import cn.suse.android.entity.User.Education;

/**
 * @author liubin
 * Create DateTime:Sep 21, 2012 10:07:34 PM
 * Description:
 * @Version: 1.0.0
 */
public class UserParse extends BaseParse<User> {

	/* (non-Javadoc)
	 * @see cn.suse.android.logic.BaseParse#parseData(java.lang.String)
	 */
	@Override
	public List<User> parseData(String content) {
		// TODO Auto-generated method stub
		List<User> lists = new ArrayList<User>();
		try {
			JSONObject jsonObject = new JSONObject(content);
			try {
				jsonObject.getString("birthday");
			} catch (Exception e) {
				jsonObject = jsonObject.getJSONArray("users").getJSONObject(0);
			}
			User user = new User();
			user.setBirthday(jsonObject.getString("birthday"));
			user.setBlood(jsonObject.getString("blood"));
			user.setBodyform(jsonObject.getString("bodyform"));
			user.setCity(jsonObject.getString("city"));
			user.setFavbook(jsonObject.getString("favbook"));
			user.setFavmovie(jsonObject.getString("favmovie"));
			user.setFavtv(jsonObject.getString("favtv"));
			user.setGender(jsonObject.getString("gender"));
			user.setHometown(jsonObject.getString("hometown"));
			user.setIdol(jsonObject.getString("idol"));
			user.setIntro(jsonObject.getString("intro"));
			user.setLogo120(jsonObject.getString("logo120"));
			user.setLogo50(jsonObject.getString("logo50"));
			user.setMarriage(jsonObject.getString("marriage"));
			user.setMotto(jsonObject.getString("motto"));
			user.setName(jsonObject.getString("name"));
			user.setOnline(jsonObject.getString("online"));
			user.setPinyin(jsonObject.getString("pinyin"));
			user.setStatus(jsonObject.getString("status"));
			user.setTrainwith(jsonObject.getString("trainwith"));
			user.setUid(jsonObject.getString("uid"));
			user.setWishlist(jsonObject.getString("wishlist"));
			user.setInterest(jsonObject.getString("interest"));
			User.Education education =user.new Education();
			try {
				JSONObject json = jsonObject.getJSONArray("education").getJSONObject(0);
				education.setClasses(json.getString("class"));
				education.setSchool(json.getString("school"));
				education.setSchooltype(json.getString("schooltype"));
				education.setYear(json.getString("year"));
				user.setEducation(education);
			} catch (Exception e) {
				user.setEducation(null);
			}
			lists.add(user);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return lists;
	}

}
